package com.wyh6635.rate.smooth;

import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.RateLimiter;

/**
 * 漏桶原理demo，按照最大的平均速率允许请求正常运行
 */
public class SmoothWarmingUpDemo {

	public static void main(String[] args) throws InterruptedException {
		RateLimiter limiter = RateLimiter.create(5, 1000, TimeUnit.MILLISECONDS);
		for(int i = 1; i < 5;i++) {
		    System.out.println(limiter.acquire());
		}
		Thread.sleep(1000L);
		for(int i = 1; i < 5;i++) {
		    System.out.println(limiter.acquire());
		}
	}
}

	